using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Nop.Data
{
	public class SQLDispatchContext
	{
		public string Region { get; set; }

		public static SQLDispatchContext GetCurrentContext()
		{
			SQLDispatchContext ctx = null;
			if (HttpContext.Current != null)
				ctx = (SQLDispatchContext)HttpContext.Current.Items["SQLDispatchContext"];
			else
				ctx = (SQLDispatchContext)System.Web.HttpRuntime.Cache["SQLDispatchContext"];
			return ctx ?? new SQLDispatchContext() { Region = string.Empty };
		}
		public static void SetCurrentContext(SQLDispatchContext ctx)
		{
			if (HttpContext.Current != null)
				HttpContext.Current.Items["SQLDispatcherContext"] = ctx;
			else
				HttpRuntime.Cache["SQLDispatcherContext"] = ctx;
		}

		public static void ResetCurrentContext()
		{
			SQLDispatchContext ctx = new SQLDispatchContext();
			ctx.Region = string.Empty;
			SetCurrentContext(ctx);
		}
	}
}
